package com.walsai.pcsys.web.controller;

import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.walsai.pcsys.core.model.Contest;
import com.walsai.pcsys.core.model.Problem;
import com.walsai.pcsys.core.model.User;
import com.walsai.pcsys.core.service.ContestManager;
import com.walsai.pcsys.core.service.ProblemManager;

public class ProblemSelectController extends SimpleFormController{
	
	private ProblemManager problemManager;
	private ContestManager contestManager;


	public void setProblemManager(ProblemManager problemManager){
		this.problemManager = problemManager;
	}
	
	public void setContestManager(ContestManager contestManager){
		this.contestManager = contestManager;
	}
	
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		Contest c = (Contest) command;
		String[] problemids = request.getParameterValues("problemids");
		for(int i = 0; i < problemids.length; i++){
			System.out.println("--------- " + problemids[i]);
		}
		//this.contestManager.save(c);
		return null;
	}
	
	protected Object formBackingObject(HttpServletRequest request) throws ServletException {
		List<Problem> lp = this.problemManager.getPrivateProblems();
		Contest c = new Contest();
		c.setProblems(lp);
		return c;
	}
	
}